package com.lcb.spring;

import com.lcb.spring.bean.Car;
import com.lcb.spring.bean.Person;
import com.lcb.spring.config.MainConfig;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Application {
    public static void main(String[] args) {
//        ClassPathXmlApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");
//        System.out.println(cxt.getBean("car"));

//        AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MainConfig.class);
////        Person person1 = (Person) cxt.getBean("person2");
////        Person person2 = (Person) cxt.getBean("person2");
////        System.out.println(person1==person2);

//        AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MainConfig.class);
//        for (String beanName : cxt.getBeanDefinitionNames()) {
//            System.out.println("beanName:" + beanName);
//        }
//        AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MainConfig.class);
//        Person person1 = (Person) cxt.getBean("person2");
//        System.out.println(person1);
//        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MainConfig.class);
//        ctx.publishEvent(new ApplicationEvent("我手动发布一个事件") {
//            @Override
//            public Object getSource() {
//                return super.getSource();
//            }
//        });
//
//        ctx.close();
        AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MainConfig.class);
        System.out.println(cxt.getBean(Car.class));

//        for (; ; ) {
//
//            RootBeanDefinition beanDefinition = new RootBeanDefinition();
//            beanDefinition.setScope("PRO");
//            beanDefinition.setLazyInit(true);
//            beanDefinition.setBeanClassName("person");
//            beanDefinition.setBeanClass(Person.class);
//        }
      //  DefaultListableBeanFactory.
        // 单例池

    }
}
